﻿#pragma once
#ifndef SerialVector_hpp
#define SerialVector_hpp

#include<vector>
#include"SerialBuffer.hpp"


namespace MMFSerialize{

    //序列化vector
    template<typename ValueT>
    SerialInBuffer& operator>>(SerialInBuffer& buff, const std::vector<ValueT>& vec)
    {
        //获取数量
        uint32_t count = (uint32_t)vec.size();

        //序列化数量
        buff >> count;

        //序列化内部数据
        for (size_t i = 0; i < count; i++)
        {
            buff >> vec[i];
        }

        return buff;
    }

    //反序列化vector
    template<typename ValueT>
    SerialOutBuffer& operator<<(SerialOutBuffer& buff, std::vector<ValueT>& vec)
    {
        //获取数量
        uint32_t count;
        buff << count;

        //修改容器数量
        vec.resize(count);

        //反序列化数据
        for (size_t i = 0; i < count; i++)
        {
            buff << vec[i];
        }

        return buff;
    }
}



#endif